﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.IO;

namespace SwHelper.Assembly
{
    internal class AssemblyHelper : IAssemblyHelper
    {
        private SldWorks swApp { get; set; }
        
        public AssemblyHelper(SldWorks _app)
        {
            this.swApp = _app;
        }
        /// <summary>
        /// 装配文档
        /// </summary>
        /// <param name="docPath"></param>
        /// <returns></returns>
        public AssemblyDoc OpenAssemblyDoc(string docPath)
        {
            AssemblyDoc assemDoc = null;
            if (File.Exists(docPath))
            {
                int IntError = 0, IntWraning = 0;
                assemDoc = (AssemblyDoc)swApp.OpenDoc6(docPath, (int)swDocumentTypes_e.swDocASSEMBLY, (int)swOpenDocOptions_e.swOpenDocOptions_LoadModel, "", ref IntError, ref IntWraning);
            }
            return assemDoc;
        }


        public object[] GetListComponent(bool isOnlyTop)
        {
            //List<Component2> listComponents = new List<Component2>();
            ModelDoc2 modleDoc = swApp.IActiveDoc2;
            if (modleDoc != null && modleDoc.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
            {
                AssemblyDoc assemblyDoc = (AssemblyDoc)modleDoc;
                object[] components = assemblyDoc.GetComponents(isOnlyTop);
                return components;
                //foreach (Component2 component in components)
                //{
                //    listComponents.Add(component);
                //}                
            }
            return null;
        }

        public void AddComponentToAssembly(string componentPath)
        {
            AssemblyDoc assemblydoc = swApp.ActiveDoc;
            if(assemblydoc != null)
            {
                assemblydoc.AddComponent5(componentPath, 0, "", false, "", 0.0, 0.0, 0.0);
            }
        }

        public void Test(int a, int b, out int c)
        {
            c = a + b;
        }
    }
        
}
